<?php
Globals::requireController('Admin');
Globals::requireTable('Productv3');

class Productv3Controller extends AdminController
{
    protected $productv3Table;
    
	public function __construct($config = null)
	{
		parent::__construct($config, true);
		$this->productv3Table = new Productv3Table($config);
	}
	
	public function indexAction()
	{
	    $where['status'] = 1;
	    $count = $this->productv3Table->listCount($where);
	    $pageSize = 20;
	    $pageId	= $this->getIntParam('page');
	    $this->view->paging = $this->getPaging($count, $pageSize,$pageId);
	    $this->view->data = $this->productv3Table->listPage($where, 'id ASC', $pageSize, $pageId);
	}
	
	public function addAction()
	{
	    $id = $this->getIntParam('id');
	    if($id > 0){
	        $product = $this->productv3Table->getRow($id);
	        if($product['id'] > 0 && $product['status'] == 1){
	            $this->view->product = $product;
	        }
	    }
	}
	
	public function doaddAction()
	{
	    $id = $this->getIntParam('id');
	    $data['name'] = $this->getParam('name1');
	    $data['img'] = $this->getParam('img');
	    $data['url'] = $this->getParam('url');
	    $data['remark'] = $this->getParam('remark');
	    $data['is_vip'] = $this->getIntParam('is_vip');
	    $data['join_url'] = $this->getParam('join_url');
	    $data['createdate'] = date('Y-m-d H:i:s');
	    if($id > 0){
	        $this->productv3Table->update($data,$id);
	    }else{
	        $this->productv3Table->add($data);
	    }
	    $this->redirectToAction();
	    exit();
	}
	
	public function deleteAction()
	{
	    $id = $this->getIntParam('id');
	    $this->productv3Table->update(array('status'=>0),$id);
	    $this->redirectToAction();
	    exit();
	}
	
}
